/* Functions to generate individual XML request messages */

function loginMessage(loginId, password, encrypted, returnEncryptedPassword) {

	var requestXml = "<Login><LoginId>" + loginId + "</LoginId><Password>" + password + "</Password>";

	if (encrypted) {
		requestXml += "<Encrypted>Yes</Encrypted>";
	} else {
		requestXml += "<Encrypted>No</Encrypted>";
	}

	if (returnEncryptedPassword) {
		requestXml += "<ReturnEncryptedPassword>Yes</ReturnEncryptedPassword>";
	}

	requestXml += "</Login>";

	return requestXml;
}

function siteInfoMessage() {
	return "<SiteInfo></SiteInfo>";
}

function loggedInMessage() {
	return "<LoggedIn></LoggedIn>";
}

function userInfoMessage() {
	return "<UserInfo></UserInfo>";
}

function boardsMessage() {
	return "<Boards></Boards>";
}

function logoutMessage() {
	return "<Logout></Logout>";
}

function newAnswersMessage(boardId) {
	return "<RecentlyUpdatedThreads><BoardId>" + boardId + "</BoardId></RecentlyUpdatedThreads>";
}

function voteMessage(boardId, threadId, optionId) {
	return "<Vote><BoardId>" + boardId + "</BoardId><ThreadId>" + threadId + "</ThreadId><OptionId>" + optionId + "</OptionId></Vote>";
}

function searchThreadTitlesMessage(queryString, offset, responses) {
	return "<Search><Offset>" + offset + "</Offset><Responses>" + responses + "</Responses><Type>ThreadTitle</Type><QueryString>" + queryString + "</QueryString></Search>";
}

function threadMessage(boardId, threadId, showImages, start, pageSize) {

	var xml = "";
	
	xml += "<Thread><BoardId>" + boardId + "</BoardId><ThreadId>" + threadId + "</ThreadId>";
	xml += "<ShowImages>" + showImages + "</ShowImages><Start>" + start + "</Start><PageSize>" + pageSize + "</PageSize>";
	xml += "</Thread>";

	return xml;
	
}


function sendMessage(requestXml, callback) {

	$.ajax({
		url : "../jaxrs/api",
		type : "POST",
		contentType : "application/xml",
		data : requestXml,
		dataType : "xml",
		cache : false,
		success : callback
	});
}